#ifndef TRGLOBAL_H
#define TRGLOBAL_H


#include <QtCore/QMap>
#include <QtCore/QDir>
#include <QtCore/QTime>
#include <QtCore/QDebug>
#include <QtCore/QVector>
#include <QtCore/QString>
#include <QtCore/QObject>
#include <QtCore/QDateTime>
#include <QtCore/QStringList>
#include "ThostFtdcUserApiStruct.h"


#if defined(TRMANAGER_LIBRARY)
#  define TRMANAGERSHARED_EXPORT Q_DECL_EXPORT
#else
#  define TRMANAGERSHARED_EXPORT Q_DECL_IMPORT
#endif

#ifdef _WIN32
#  define AppPath QDir::currentPath()
#else
#  define AppPath QDir::currentPath()
#endif

#define TIMEMS qPrintable (QTime::currentTime().toString("HH:mm:ss zzz"))
#define TIME qPrintable (QTime::currentTime().toString("HH:mm:ss"))
#define QDATE qPrintable (QDate::currentDate().toString("yyyy-MM-dd"))
#define QDATE_S qPrintable (QDate::currentDate().toString("yyyyMMdd"))
#define QDATE_QUOTE qPrintable (QDate::currentDate().toString("yyyyMMdd HH:mm:ss"))
#define QTIME qPrintable (QTime::currentTime().toString("HH-mm-ss"))
#define QTIMEZ qPrintable (QTime::currentTime().toString("HH-mm-ss-zzz"))
#define QTIMEZ_IN_TRADING qPrintable (QTime::currentTime().toString("HHmmsszzz"))
#define QTIMEZ_FORLOG qPrintable (QTime::currentTime().toString("HHmmss"))
#define DATETIME qPrintable (QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
#define STRDATETIME qPrintable (QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"))
#define STRDATETIMEMS qPrintable (QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss-zzz"))

enum class Tr_UserLoginStatus
{
    OffLine = 0,
    OnLine  = 1,
    Logging = 2,
    Completed = 3
};

enum class Tr_InstrumentStatus
{
    NoData = 0,
    Updatting = 1,
    Successed = 2
};

enum class Tr_InvestorPositionStatus
{
    NoQuery = 0,
    Querying = 1,
    Ready = 2
};

enum class Tr_ResponseID
{
    TrMarketUserLogin			= 100,
    TrOnRspUserLogin            = 101,
    TrOnRspUserLogout           = 102,
    TrOnRtnDepthMarketData		= 103,
    TrOnRspQryTradingAccount	= 104,
    TrOnInvestorPositions       = 105,
    TrOnRspQryInvestorPosition	= 106,
    TrOnRtnOrder				= 107,
    TrOnRtnTrade				= 108,
    TrOnRspError				= 109,
    TrOnRspOrderInsert			= 110,
    TrOnRspQryInstrument		= 111,
    TrOnDailyHistoryQuote       = 112,
    TrOnMiniHistoryQuote        = 113
};

struct TrRtnOrderField
{
    TThostFtdcInstrumentIDType  InstrumentID;
    int                         Lots;
    double                      LimitPrice;
    int                         Offset;
    char                        source[50];
};

#define TrColor_Red     QColor(255, 60, 60)
#define TrColor_Green   QColor(0, 175, 100)
#define TrColor_Blue    QColor(0, 70, 255)
#define TrColor_White   QColor(255, 255, 255)
#define TrColor_Black   QColor(0, 0, 0)

#define MESSAGE_ONTRADE WM_USER + 10


#pragma pack(push,1)

#define TR_MAX_PACKET_SIZE    256

enum class Tr_RequestCommand
{
    // some day tick
    TR_CMD_REQUEST_ONEDAYTICK = 1001,
    // all day kline
    TR_CMD_REQUEST_DAYKLINE     =   1002
};




typedef struct Tr_UserInfo
{
    TThostFtdcInstrumentIDType  InstrumentID;
    TThostFtdcUserIDType        UserID;
    TThostFtdcBrokerIDType      BrokerID;
    TThostFtdcDateType          TradingDay;
} t_userinfo;

typedef struct Tr_Header
{
    Tr_RequestCommand           cmd;
    char                        crc[16];
    char                        verison[13];
    int                         size;
    t_userinfo                  userinfo;
} t_header;

typedef struct Tr_Packet
{
    t_header				header;
    char					data[TR_MAX_PACKET_SIZE];
    bool                    bIsLast;
} packet;

typedef struct Tr_DaySettleRecode
{
    TThostFtdcDateType          TradingDay;
    TThostFtdcPriceType         OpenPrice;
    TThostFtdcPriceType         HighestPrice;
    TThostFtdcPriceType         LowestPrice;
    TThostFtdcVolumeType        Volume;
    TThostFtdcMoneyType         Turnover;
    TThostFtdcLargeVolumeType	OpenInterest;
    TThostFtdcPriceType         ClosePrice;
} t_DaySettleRecode;

typedef struct Tr_TickData
{
    TThostFtdcDateType	TradingDay;
    TThostFtdcInstrumentIDType	InstrumentID;
    TThostFtdcPriceType	LastPrice;
    TThostFtdcLargeVolumeType	PreOpenInterest;
    TThostFtdcPriceType	OpenPrice;
    TThostFtdcPriceType	HighestPrice;
    TThostFtdcPriceType	LowestPrice;
    TThostFtdcVolumeType	Volume;
    TThostFtdcMoneyType	Turnover;
    TThostFtdcLargeVolumeType	OpenInterest;
    TThostFtdcTimeType	UpdateTime;
    TThostFtdcMillisecType	UpdateMillisec;
    TThostFtdcPriceType	BidPrice1;
    TThostFtdcVolumeType	BidVolume1;
    TThostFtdcPriceType	AskPrice1;
    TThostFtdcVolumeType	AskVolume1;
} t_TickData;

#pragma pack(pop)


#endif // TRGLOBAL_H
